var app = getApp();
var util = require('../../utils/util.js');
var one_id = 0;
var two_id = 0;
Component({
  options: {
    addGlobalClass: true  //使用app.wxss
  },
  /**
   * 组件的属性列表
   */
  properties: {
    isShowSuperList:{ 
      type:Number  //是否显示组件
    },
    btm_distance:{
      type:Number  //底部距离，导航页为50，其他页为0
    },
    loginInfo:{
      type:Object  //门店基本信息
    },
    gun:{
      type:Boolean
    },
    type_level:{
      type:String, //普通版or独立版
    },
    group_id:{
      type:String, //所加入的集团id
    },
    group_name:{   //所加入的集团名称
      type:String
    },
  },
  detached() {  //在组件实例被从页面节点树移除时执行
    one_id = 0;
    two_id = 0;
  },
  /**
   * 组件的初始数据
   */
  data: {
    Capsule:app.globalData.Capsule,
    CustomBar:app.globalData.CustomBar,
    Capsulehei:app.globalData.Capsulehei,
    phonetype:app.globalData.phonetype,
    // *************************************
    bar_List:['商品','常用'],
    page_type:0, //0商品库，1常用
    is_start: false,  //是否执行了touchStart
    is_move: false,   //是否执行了touchMove
    isinput_col: false,  //收藏弹窗显隐
    ischoose_index: -1,   //选中规格样式 
    isInput: false,  //添加商品数量弹框及输入框焦点
    isInput2: false,  //特殊需求备注弹框的输入框焦点
    istszh: false,  //特殊需求备注弹框
    inputNum: "",   //添加商品弹窗的输入框中数量
    inputIndex:-1,    //主产品索引值
    isfeibiao: false,  //添加非标品弹窗的显隐
    fbName: '',  //非标品名称
    fbNum: 0,   //非标品数量
    inputFBNum: "",  //非标品弹窗的输入框中数量
    types: [],  //一级分类列表
    leftTypes:[],  //二级分类列表
    choose:0,     //一级分类初始索引值
    leftChoose: 0,  //二级分类初始索引值
    unit_list:[],  //单位列表
    firstPerson: '',  //非标品的单位
    value: '',   //非标品的单位索引值
    tanimg:"",   //弹窗商品图片
    tanname: "",  //弹窗商品名称
    tanunit: "",  //弹窗商品单位
    tangui:"",   //弹窗规格名称
    tannum:"",   //弹窗商品数量
    hide_good_box: true,  //动画小球的显隐
    tszhinput:"",     //备注输入框内容
    tszhcontent:"",   //备注内容
    page:1,     //当前页码
    load: "加载中...",
    selectdanwei: false,  //选择单位弹窗
    rightDatas:[],
    KeyboardKeys: [1, 2, 3, 4, 5, 6, 7, 8, 9, '·', 0], //键盘
    content:'', //键盘初始空字符串
    total:0,
    isedit: false,  //是否编辑
    shopnum: '',  //商品数量
    is_checked: {},  //选中状态
    leftChoose_col: 0, //左侧初始索引值(常用)
    shoppr_num: '', //选中的商品是否已添加
    nocoll:1,  //0表示暂无数据
    checked_len:0, //选中商品
    load_num:1,
    loading:1,
    assign_super_index:-1,  //选择的供应商
    tan_is_auxiliary:0,  //当前商品是否开启辅助单位  0关闭，1开启
    aux_kucun_index:-1,   //库存商品辅助单位索引
    z_choose_supplier_id:-1,  //fb中选择的供应商
    tan_shop_ku:0,  //当前商品是否属于库商品
    is_cancel_apply:false,  //是否取消申请供应商
    is_go_create:false,  //提示去创建
    assign_superlist:[],
    aux_kucun_list:[],
    btm_superlist:[],
    is_move_gif:false,  //按钮动图
    intro_opac_0:1,  //页面上拉后透明度变化
    intro_opac_1:0,  //页面上拉后透明度变化
    topNum:0,  //区域滚动回到顶部
  },
  pageLifetimes: {
    show() {
      // 页面被展示
      this.busPos = {};
      this.busPos['x'] = app.globalData.ww * 0.1;
      this.busPos['y'] = app.globalData.hh * 0.9;
      if(this.data.load_num==0){
        if(this.data.page_type==0){
          this.upshoplist();
        }else{
          this.upshoplist_often();
        };
        util.car_total(this,-1,1);
      };
    },
    hide() {
      // 页面被隐藏
    },
    resize(size) {
      // 页面尺寸变化
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    open_onload(left_height,coll_right_h){
      var that = this; 
      let loginInfo=that.data.loginInfo;
      let screen_height=wx.getSystemInfoSync().windowHeight-app.globalData.CustomBar;  //显示区高度
      that.setData({
        PAGE_H:wx.getSystemInfoSync().windowHeight,
        PAGE_W:wx.getSystemInfoSync().windowWidth,
        RPX190:190/750 * wx.getSystemInfoSync().windowWidth,
        RPX280:280/750 * wx.getSystemInfoSync().windowWidth,
        RPX270:270/750 * wx.getSystemInfoSync().windowWidth,
        supername:loginInfo.client_abbre,
        good_dir_set:loginInfo.good_dir_set,
        client_is_store:loginInfo.client_is_store,
        purchase_type:loginInfo.purchase_type,
        left_height:left_height,
        coll_right_h:coll_right_h,
        unit_height:0.64* screen_height,
        two_specs_h:0.5* screen_height,
        raplace_h:0.75*screen_height-50
      })
      if(that.data.page_type==0){
        that.upshoplist();
      }else{
        that.upshoplist_often();
      };
      util.car_total(that,-1,1);
      this._observer = wx.createIntersectionObserver(this,{thresholds:[0,0.2,0.4,0.6,0.7,0.8,1]});
      this._observer
        .relativeTo('.fix_box')
        .observe('.intro_empty_114', (res) => {
          let intro_opac_0=this.data.gun?0:1-res.intersectionRatio;
          let intro_opac_1=this.data.gun?1:res.intersectionRatio;
          this.setData({
            intro_opac_0:intro_opac_0,
            intro_opac_1:intro_opac_1
          })  
      });
    },
    // 返回顶部
    back_top(){
      wx.pageScrollTo({
        scrollTop: 0
      });
    },
    touchStart(e){
      let sx = e.touches[0].pageX;
      let sy = e.touches[0].pageY;
      this.data.touchS = [sx, sy];
      this.setData({
        is_start: true
      });
    },
    touchMove(e){
      let sx = e.touches[0].pageX;
      let sy = e.touches[0].pageY;
      this.data.touchE = [sx, sy];
      this.setData({
        is_move: true
      });
    },
    touchEnd(e){
      if (this.data.is_start == true && this.data.is_move == true){
        let start = this.data.touchS;
        let end = this.data.touchE;    
        var t_sy=end[1] - start[1]; //y轴滑动方向及距离
        if(t_sy<0 && !this.data.gun){
          this.setData({
            gun:true
          });
          wx.pageScrollTo({
            scrollTop:this.data.RPX190+this.data.CustomBar
          });
        }else if(t_sy>0 && this.data.gun){
          this.setData({
            gun:false
          });
          wx.pageScrollTo({
            scrollTop:0
          });
          wx.stopPullDownRefresh();
        };
        this.setData({
          is_start: false,
          is_move: false
        });
      }; 
    },
    touchEndfix(e){
      if (this.data.is_start == true && this.data.is_move == true){
        let start = this.data.touchS;
        let end = this.data.touchE;    
        var t_sy=end[1] - start[1]; //y轴滑动方向及距离
        if(t_sy>0 && this.data.gun){
          this.setData({
            gun:false
          });
          wx.pageScrollTo({
            scrollTop:0
          });
        };
        this.setData({
          is_start: false,
          is_move: false
        });
      }; 
    },
    //事件集合
    // 切换导航
    typebar_Tap(e){
      var index=e.currentTarget.dataset.index;
      this.setData({
        topNum:0,
        page_type:index,
        scrollLeft:0
      });
      if(index==0){
        this.upshoplist();
      }else if(index==1){
        this.upshoplist_often();
      };
    },
    // 扫描商品条码
    saomiao_ck(){
      wx.scanCode({
        onlyFromCamera:true,   //值为 false  既可以使用相机也可以使用相册，  值为true 只能使用相机
        //  scanType:['barCode', 'qrCode','datamatrix','pdf417'], 
         //分别对应 一维码  二维码  DataMatrix码  PDF417条码  
        success: (res) => { //扫码成功后
          console.log(res)
          wx.showToast({
            title: '扫码成功',
            duration: 1000,
            mask: true
          });
          wx.navigateTo({
            url: '/shop_car_space/pages/shop_car/shop_car?supplier_id=' + "-1" + '&supername=' + this.data.supername+ '&is_ku=' + 1+'&price_type='+1+'&show_price_type='+'A'+'&is_sao_code='+1+'&sao_code='+res.result
          });
         },
         fail: (res) => {//扫码失败后
            wx.showToast({
               title: '扫码失败',
               icon: 'loading',
               duration: 1500
            })
         },
         complete:(res)=>{}
       })
    },
    // 去购物车页面
    gouWuCheTap(){  
      wx.navigateTo({
        url: '/shop_car_space/pages/shop_car/shop_car?supplier_id=' + "-1" + '&supername=' + this.data.supername+ '&is_ku=' + 1+'&price_type='+1+'&show_price_type='+'A'
      });
    },
    noneEnoughPeople(){
      return;
    },
    // 打开特殊需求备注弹窗
    opentszh(){
      this.setData({
        tszhinput: this.data.tszhcontent,
        isInput2:true,
        istszh: true
      })
    },
    // 特殊需求备注弹窗输入内容
    tszhinput(e){
      this.setData({
        tszhinput: e.detail.value
      });
    },
    // 关闭特殊需求备注弹窗
    tszhcancel(){
      this.setData({
        isInput2: false,
        istszh: false
      })
    },
    // 确定并关闭需求备注弹窗
    tszhconfirm(){
      this.setData({
        isInput2: false,
        istszh: false,
        tszhcontent: this.data.tszhinput
      })
    },
    //点击切换
    mySelect(e){  
      util.hideBuyModal(this,"selectdanwei");
      this.setData({
        firstPerson: e.target.dataset.me,
        value: e.target.dataset.value
      })
    },
    // 非标品单位列表
    feibiao(){
      var that = this;
      app.AppHttp('api/Goods/addNoProduct',{}, function (res) {
        that.setData({
          unit_list: res.data.unit_list
        })
      })
    },
    // 一级分类切换
    typeClick(event){
      let offsetTop = event.currentTarget.offsetTop;
      this.setData({
        topNum:0,
        scrollLeft: offsetTop - this.data.left_height/2,
        sole:0,
        choose: event.currentTarget.dataset.index,
        leftChoose:0,
        page: 1,
        load: "加载中..."
      });
      one_id = this.data.types[this.data.choose].private_one_class;
      two_id = 0;
      this.upshoplist();
    },
    // 二级分类切换
    leftClick(event) {
      let offsetLeft = event.currentTarget.offsetLeft;
      this.setData({
        topNum:0,
        scroll_more: offsetLeft - (0.7*wx.getSystemInfoSync().windowWidth)/2,
        leftChoose: event.currentTarget.id,
        page: 1,
        load: "加载中..."
      });
      var that = this;
      one_id = that.data.types[that.data.choose].private_one_class;
      two_id = that.data.leftTypes[that.data.leftChoose].private_one_class;
      that.upshoplist();
    },
    //供应商未报价
    zero_price_but(){
      wx.showLoading({
        title:'供应商未报价',
        duration:500
      })
    },
    // 打开规格的收藏内容
    spesc_but(e){
      var index = e.currentTarget.id;
      var is_up=e.currentTarget.dataset.is_up;  //是否下架及供应商数量
      var is_ku=e.currentTarget.dataset.is_ku;  //当前商品是否属于库存商品
      var is_zi_cai=this.data.loginInfo.is_zi_cai;  //是否自采
      var specs_count=e.currentTarget.dataset.specs_count;  //是否多规格
      var tan_is_auxiliary=e.currentTarget.dataset.is_auxiliary;  //是否开启辅助单位
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){
        if(is_up*1+is_zi_cai*1==0 && is_ku==0){
          return;
        };
        if(is_ku==1){   //库存商品
          this.setData({
            is_move_gif:tan_is_auxiliary==1?true:false,
            tan_shop_ku:1,
            aux_kucun_index:-1,
            aux_kucun_list:[],
            tan_is_auxiliary:tan_is_auxiliary
          });
          if(tan_is_auxiliary==1){
            this.aux_kucun_fun(e.currentTarget.dataset.shopid);
          };
        }else if(is_ku==0){  //非库存商品
          this.setData({
            tan_shop_ku:0,
            tan_is_auxiliary:tan_is_auxiliary,
            assign_superlist:[],
            is_move_gif:true,
          });
          if(specs_count==0){  //仅有主规格
            this.assign_super_fun(e.currentTarget.dataset.shopid,tan_is_auxiliary);
          };  
        };
      }else{
        this.setData({
          tan_is_auxiliary:tan_is_auxiliary,
          is_move_gif:false
        });
      };
      this.setData({
        shopid: e.currentTarget.dataset.shopid,
        show_index:index,
        shop_is_same:this.data.rightDatas[index].is_same,
        ischoose_index: -1,
        tszhcontent: ''
      });
      this.tancontent();    
    },
    // 收藏弹窗内容展示
    tancontent(){
      var that = this;
      app.AppHttp('api/Shopping/addCoolGoodsPage', {
        openid: app.globalData.openid,
        good_id: that.data.shopid,
        is_ku:1
      }, function (res) {
        that.setData({
          taninfo: res.data,    //弹窗数据
          isinput_col: true,
          shopnum: '',
          shoppr_num: '',
          assign_super_index:-1
        })
        if (res.data.specs_list.length == 1) {
          that.setData({
            ischoose_index: 0,  //当规格只有一个时为选中状态
            tszhcontent: res.data.specs_list[0].remark?res.data.specs_list[0].remark:'', 
            shoppr_num: res.data.specs_list[0].pr_num,  //选中的产品是否已添加
            shop_price_type:res.data.specs_list[0].price_type,  //选中的产品价格类型
            shop_price:res.data.specs_list[0].true_price, //选中的产品的价格
            shop_sale_price:res.data.specs_list[0].sale_price,  //选中的产品销售价
            tan_ku_price:that.data.shop_is_same==0?res.data.specs_list[0].stock_sale_price:res.data.specs_list[0].stock_price_show,
            tan_ku_num:res.data.specs_list[0].stock_num_show,
            is_tan_ku_price:res.data.specs_list[0].is_show_stock_price,
            is_tan_ku_num:res.data.specs_list[0].is_show_stock_num
          });
        }else{
          that.setData({
            assign_superlist:[],
            aux_kucun_list:[]
          });
        }
      });
    },
    // 选定条件后打开底部弹窗
    open_tan_info(e){
      if(this.data.ischoose_index>=0){
        util.showBuyModal(this);
        var taninfo = this.data.taninfo;
        if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){   //模式5
          if(this.data.tan_shop_ku==1){    //库存商品
            if(this.data.tan_is_auxiliary==0){   //未开启辅助单位
              this.setData({
                assign_super_index:-1,
                aux_kucun_index:-1,
                aux_kucun_list:[],
              });
            }else if(this.data.tan_is_auxiliary==1){  //开启了辅助单位
              if(this.data.aux_kucun_list.length==1){  //仅有一条辅助单位
                this.setData({
                  assign_super_index:-1,
                  aux_kucun_index:0,
                  shoppr_num: this.data.aux_kucun_list[0].pr_num,
                });
              }else{
                this.setData({
                  assign_super_index:-1,
                  aux_kucun_index:e.currentTarget.dataset.index,
                  shoppr_num: this.data.aux_kucun_list[e.currentTarget.dataset.index].pr_num,
                });
              };     
            };
          }else if(this.data.tan_shop_ku==0){  //非库存商品 
            if(this.data.assign_superlist.length==0){  //自采
              this.setData({
                aux_kucun_index:-1,
                aux_kucun_list:[],
                assign_super_index:-10010
              });
              this.zicai_pr_num(taninfo.specs_list[this.data.ischoose_index].id);
            }else if(this.data.assign_superlist.length==1 && this.data.loginInfo.is_zi_cai==0){  //仅一个供应商+未开自采
              this.setData({
                aux_kucun_index:-1,
                aux_kucun_list:[],
                assign_super_index:0,
                shoppr_num:this.data.assign_superlist[0].pr_num
              });
            }else{
              if(e.currentTarget.dataset.index!=-10010){
                this.setData({
                  shoppr_num:this.data.assign_superlist[e.currentTarget.dataset.index].pr_num
                });
              }else if(e.currentTarget.dataset.index==-10010){
                this.zicai_pr_num(taninfo.specs_list[this.data.ischoose_index].id);
              };
              this.setData({
                aux_kucun_index:-1,
                aux_kucun_list:[],
                assign_super_index:e.currentTarget.dataset.index
              });  
            }               
          }  
        };
        this.setData({
          content:'',
          isInput: true,
          tanimg: taninfo.goodInfo.cover,
          tanname: taninfo.goodInfo.trade_name,
          tanalias:taninfo.goodInfo.trade_alias,
          tanspecs:taninfo.specs_list[this.data.ischoose_index].specs,
          tanunit_index:taninfo.specs_list[this.data.ischoose_index].help_unit>0?taninfo.specs_list[this.data.ischoose_index].help_unit:taninfo.specs_list[this.data.ischoose_index].unit,
          tanunit: taninfo.specs_list[this.data.ischoose_index].help_unit>0?taninfo.specs_list[this.data.ischoose_index].help_unit_name:taninfo.specs_list[this.data.ischoose_index].unit_name,
          tanunit_init: taninfo.specs_list[this.data.ischoose_index].unit_name,
          tan_true_price:taninfo.specs_list[this.data.ischoose_index].true_price,
          tan_sale_price:taninfo.specs_list[this.data.ischoose_index].sale_price,
          tan_price_type: taninfo.specs_list[this.data.ischoose_index].price_type,
        });
      }else{
        wx.showLoading({
          title:'请选择规格',
          duration:500
        })
      };
    },
    col_setValue(){
      this.setData({
        shopnum: this.data.content
      });
    },
    // 取消关闭添加商品弹窗
    cancel_col(){
      this.setData({
        isinput_col: false
      });
    },
    // 选择商品规格
    chose_specs(e){  
      var index = e.currentTarget.dataset.index;
      var item=this.data.taninfo.specs_list[index];
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1 && this.data.tan_shop_ku==0 && item.tan_is_auxiliary==1 && index>0){
        wx.showModal({
          title: '提示',
          content:'当非库存商品开启辅助单位功能后，商品其他规格则被锁定',
          showCancel: false,
          confirmText:"我知道了",
          success: function (res) {}
        });   
        return;
      }else if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1 && this.data.tan_shop_ku==0 && (item.is_auxiliary==1 && item.is_aux_up*1+this.data.loginInfo.is_zi_cai*1==0 || item.is_auxiliary==0 && item.is_up*1+this.data.loginInfo.is_zi_cai*1==0)){
        wx.showModal({
          title: '提示',
          content:'当前规格无可选供应商',
          showCancel: false,
          confirmText:"我知道了",
          success: function (res) {}
        });
        return;
      };
      var is_zi_cai=this.data.loginInfo.is_zi_cai;
      this.setData({
        assign_super_index:-1,
        aux_kucun_index:-1,
        ischoose_index: index,
        tszhcontent:item.remark?item.remark:"",
        shopid:item.id,  //选中的产品id
        shoppr_num:item.pr_num,  //选中的产品是否已添加
        shop_price_type:item.price_type,  //选中的产品价格类型
        shop_price:item.true_price, //选中的产品的价格
        shop_sale_price:item.sale_price,  //选中的产品销售价
        tan_is_auxiliary:item.is_auxiliary,  //当前规格辅助单位是否开启
        shop_is_same:item.is_same,  //是否开启采销同价
        tan_ku_price:item.is_same==0?item.stock_sale_price:item.stock_price_show,
        tan_ku_num:item.stock_num_show,
        is_tan_ku_price:item.is_show_stock_price,
        is_tan_ku_num:item.is_show_stock_num,
        assign_superlist:[],
        aux_kucun_list:[]
      });
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1 && this.data.tan_shop_ku==0){   //模式5+非库存商品
        this.setData({
          is_move_gif:true
        });
        this.assign_super_fun(item.id,this.data.tan_is_auxiliary);      
      }else{
        this.setData({
          is_move_gif:this.data.tan_is_auxiliary==1?true:false
        });
        if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1 && this.data.tan_shop_ku==1 && this.data.tan_is_auxiliary==1){  //库存+辅助
          this.aux_kucun_fun(item.id);   
        }else{
          this.open_tan_info();
        };
      }
    },
    // 添加并收藏的接口
    addorder(e){
      var that = this;
      var shopnum = that.data.shopnum;
      if (that.data.ischoose_index == -1) {
        wx.showLoading({
          title: '请选择规格',
          duration: 500
        });
        return;
      }else if(that.data.shopnum==0){
        if(that.data.shopnum != ''){ //输入0
          shopnum=0;
        }else if(that.data.shopnum == ''){ //不输入
          shopnum = that.data.shoppr_num;
        };
        if(shopnum==0){
          wx.showLoading({
            title:'输入不能为0',
            duration:500
          });
          return;
        };
      };
      if (shopnum>9999.99){
        wx.showToast({
          title: '数量过大'
        })
        return;
      };
      var aux_obj={'is_aux':0,'pr_unit':that.data.tanunit_index,'sub_unit_num':1};
      if(that.data.shop_price_type==1 || that.data.shop_price_type==2){    //非企业独立版
        app.myMethod.updateGood(-1,0,that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_price,that.data.shop_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      }else if(that.data.shop_price_type==3){
        if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){ //模式5
          if(this.data.tan_shop_ku==1){
            if(this.data.loginInfo.is_ctrl_stock==1 && shopnum>0 && shopnum*1>this.data.tan_ku_num*1){
              wx.showLoading({
                title:'库存不足',
                duration:500
              });
              return;
            };
            var kucun_price_obj={'true_price':that.data.tan_ku_price,'single_price':0};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              if(that.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
                return;
              };
              var aux_item=that.data.aux_kucun_list[that.data.aux_kucun_index];
              aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
              if(this.data.shop_is_same==0){  //是否开启采销同价
                kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
              }else if(this.data.shop_is_same==1){
                kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
              };
            };
            app.myMethod.updateGood(-1,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          }else if(this.data.tan_shop_ku==0){
            if(this.data.loginInfo.is_zi_cai==0 || that.data.assign_super_index>-1){  //非自采
              if(that.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
                return;
              };
              var assign_item=that.data.assign_superlist[that.data.assign_super_index];
              var nor_price_obj={'true_price':that.data.shop_price,'single_price':0};
              if(this.data.tan_is_auxiliary==1){  //是辅助单位
                aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
                nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
              };
              app.myMethod.updateGood(-1,assign_item.supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
            }else if(this.data.loginInfo.is_zi_cai==1 && that.data.assign_super_index==-10010){    //自采
              app.myMethod.updateGood(-10010,-10010,that.data.shopid,shopnum,that.data.tszhcontent,that.data.shop_price,0,1,0,that.data.tanunit_index,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
            };   
          };     
        }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){  //模式6,7
          app.myMethod.updateGood(-1,this.data.group_id,that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{   //模式1,4及其他
          app.myMethod.updateGood(-1,0,that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        };   
      }else if(that.data.shop_price_type==4){
        if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
          if(this.data.tan_shop_ku==1){
            if(this.data.loginInfo.is_ctrl_stock==1 && shopnum>0 && shopnum*1>this.data.tan_ku_num*1){
              wx.showLoading({
                title:'库存不足',
                duration:500
              });
              return;
            };
            var kucun_price_obj={'true_price':that.data.tan_ku_price,'single_price':that.data.tan_ku_price};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              if(that.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
                return;
              };
              var aux_item=that.data.aux_kucun_list[that.data.aux_kucun_index];
              aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
              if(this.data.shop_is_same==0){  //是否开启采销同价
                kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
              }else if(this.data.shop_is_same==1){
                kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
              };
            };
            app.myMethod.updateGood(-1,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          }else if(this.data.tan_shop_ku==0){
            if(this.data.loginInfo.is_zi_cai==0 || that.data.assign_super_index>-1){  //非自采
              if(that.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
                return;
              };
              var assign_item=that.data.assign_superlist[that.data.assign_super_index];
              var nor_price_obj={'true_price':assign_item.unit_price,'single_price':assign_item.unit_price};
              if(this.data.tan_is_auxiliary==1){  //是辅助单位
                aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
                nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
              };
              app.myMethod.updateGood(-1,assign_item.supplier_id,that.data.shopid,shopnum,that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
            }else if(this.data.loginInfo.is_zi_cai==1 && that.data.assign_super_index==-10010){  //自采
              app.myMethod.updateGood(-10010,-10010,that.data.shopid,shopnum,that.data.tszhcontent,that.data.shop_price,that.data.shop_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
            };  
          };   
        }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){  //模式6,7
          app.myMethod.updateGood(-1,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,that.data.shop_price,that.data.shop_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{   //模式1,4及其他
          app.myMethod.updateGood(-1,0,that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_price,that.data.shop_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        };
      }else if(that.data.shop_price_type==5){
        if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
          if(this.data.tan_shop_ku==1){
            if(this.data.loginInfo.is_ctrl_stock==1 && shopnum>0 && shopnum*1>this.data.tan_ku_num*1){
              wx.showLoading({
                title:'库存不足',
                duration:500
              });
              return;
            };
            var kucun_price_obj={'true_price':that.data.tan_ku_price,'single_price':that.data.tan_ku_price};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              if(that.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
                return;
              };
              var aux_item=that.data.aux_kucun_list[that.data.aux_kucun_index];
              aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
              if(this.data.shop_is_same==0){  //是否开启采销同价
                kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
              }else if(this.data.shop_is_same==1){
                kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
              };
            };
            app.myMethod.updateGood(-1,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          }else if(this.data.tan_shop_ku==0){
            if(this.data.loginInfo.is_zi_cai==0 || that.data.assign_super_index>-1){  //非自采
              if(that.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
                return;
              };
              var assign_item=that.data.assign_superlist[that.data.assign_super_index];
              var nor_price_obj={'true_price':assign_item.unit_price,'single_price':assign_item.unit_price};
              if(this.data.tan_is_auxiliary==1){  //是辅助单位
                aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
                nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
              };
              app.myMethod.updateGood(-1,assign_item.supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
            }else if(this.data.loginInfo.is_zi_cai==1 && that.data.assign_super_index==-10010){  //自采
              app.myMethod.updateGood(-10010,-10010,that.data.shopid, shopnum,that.data.tszhcontent,that.data.shop_sale_price,that.data.shop_sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
            };     
          };    
        }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){   //模式6,7
          app.myMethod.updateGood(-1,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,that.data.shop_sale_price,that.data.shop_sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{    //其他模式
          app.myMethod.updateGood(-1,0,that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_sale_price,that.data.shop_sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        };
      };
      if(this.data.isInput==true){
        util.hideBuyModal(this,"isInput");
      };
      that.setData({
        isinput_col: false
      });
      if(this.data.page_type==0){
        if(this.data.taninfo.specs_list.length==1){  //一条规格时
          that.setData({
            ["rightDatas[" + that.data.show_index + "].pr_num"]:shopnum
          });
        };
        if (shopnum > 0) {    //添加商品数量大于0时，执行抛物线方法
          util.touchOnGoods(that,e.touches["0"],-1,'nopand',1);
          that.setData({
            ["rightDatas[" + that.data.show_index + "].is_show"]: 1
          });
        } else {
          util.car_total(that,-1,1);
          this.data.taninfo.specs_list[that.data.ischoose_index].pr_num=0;
          for (var i in that.data.taninfo.specs_list){
            if (that.data.taninfo.specs_list[i].pr_num>0){
              that.setData({
                ["rightDatas[" + that.data.show_index + "].is_show"]: 1
              });
              return;
            }
          }
          that.setData({
            ["rightDatas[" + that.data.show_index + "].is_show"]: 0
          });
        }
      }else if(this.data.page_type==1){
        var coll_list = that.data.coll_list;
        if (that.data.upshop == 1) {
          that.upshoplist_often();
          util.car_total(that,-1,1);
          that.setData({
            isinput_col: false
          });
          return;
        }
        if (shopnum>0){    //添加商品数量大于0时，执行抛物线方法
          util.touchOnGoods(that,e.touches["0"],-1,'nopand',1);
          if (that.data.shopck_id == that.data.shopid) {
            coll_list[that.data.one_index][that.data.eal].is_already = 1;
          };
        }else{
          if (that.data.shopck_id == that.data.shopid) {
            coll_list[that.data.one_index][that.data.eal].is_already = 0;
          };
          util.car_total(that,-1,1);
        };
        that.setData({
          isinput_col: false,
          coll_list: coll_list
        });
      }
    },
    // 商品数量弹窗
    itemAddClick(e){
      this.numInput(e);
    },
    // 商品数量弹窗
    numInput(e){
      var index = e.currentTarget.id;
      var info = this.data.rightDatas[index];
      var is_up=e.currentTarget.dataset.is_up;   //是否有供应商
      var is_ku=e.currentTarget.dataset.is_ku;   //是否属于库存商品
      var is_zi_cai=this.data.loginInfo.is_zi_cai;   //客户是否自采
      var tan_is_auxiliary=e.currentTarget.dataset.is_auxiliary;  //是否开启辅助单位
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
        if(is_up*1+is_zi_cai*1==0 && is_ku==0){
          return;
        };
        if(is_ku==0){ 
          this.setData({
            tan_shop_ku:0,  //当前商品不属于库商品
            assign_superlist:[]
          });
          if(is_zi_cai==0){  //非自采
            this.setData({
              is_move_gif:true,
              tan_is_auxiliary:tan_is_auxiliary,
              assign_super_index:0,
              aux_kucun_index:-1,
              aux_kucun_list:[],
            });
            this.assign_super_fun(info.id,tan_is_auxiliary);
          }else if(is_zi_cai==1){  //自采
            this.setData({
              assign_super_index:-10010,
              aux_kucun_index:-1,
              aux_kucun_list:[],
              is_move_gif:false,
              tan_is_auxiliary:tan_is_auxiliary,
            });
          };   
        }else if(is_ku==1){
          if(this.data.loginInfo.is_ctrl_stock==1 && info.stock_num_show<=0){
            wx.showLoading({
              title:'库存不足',
              duration:500
            });
            return;
          };
          this.setData({
            tan_is_auxiliary:tan_is_auxiliary,
            assign_super_index:-1,
            aux_kucun_index:tan_is_auxiliary==1?0:-1,
            is_move_gif:tan_is_auxiliary==1?true:false,
            tan_shop_ku:1  //当前商品属于库商品
          });
          if(tan_is_auxiliary==1){
            this.aux_kucun_fun(info.id);
          };
        };  
      }else{
        this.setData({
          tan_is_auxiliary:tan_is_auxiliary,
          assign_super_index:-1,
          is_move_gif:false
        });
      };   
      util.showBuyModal(this);
      this.setData({
        content:'',
        tszhcontent:'',
        isInput: true,
        inputIndex: index,
        inputNum: '',
        tanimg: info.cover,
        tanname: info.trade_name,
        tanalias:info.trade_alias,
        tanspecs:info.specs,
        tanunit_index: info.help_unit>0?info.help_unit:info.unit,
        tanunit: info.help_unit>0?info.help_unit_name:info.unit_name,
        tanunit_init:info.unit_name,
        tannum: info.pr_num,
        tan_price_type:info.price_type,
        tan_true_price:info.true_price,
        tan_sale_price:info.sale_price,
        shop_is_same:info.is_same,  //是否开启了采销同价
        tan_ku_price:info.is_same==0?info.stock_sale_price:info.stock_price_show,
        tan_ku_num:info.stock_num_show,
        is_tan_ku_price:info.is_show_stock_price,
        is_tan_ku_num:info.is_show_stock_num
      });  
    },
    // 选择菜品时的供应商和价格
    assign_super_fun(good_id,is_aux){
      var that = this; 
      app.AppHttp('api/Shopping/getGoodSupplierInfo', {
        order_id:0,
        client_id: app.globalData.loginInfo.id,
        good_id:good_id,
        is_aux:is_aux
      }, function (res) {
        that.setData({
          is_move_gif:false,
          assign_superlist:res.data
        });  
        if(that.data.loginInfo.is_zi_cai==1){  //开通自采
          that.zicai_pr_num(good_id);
        };
        if(that.data.isinput_col && (res.data.length==0 && that.data.loginInfo.is_zi_cai==1 || res.data.length==1 && that.data.loginInfo.is_zi_cai==0)){   //当收藏弹窗显示时，才有可能调用
          that.open_tan_info();
        };
      });  
    },
    // 库存辅助单位接口
    aux_kucun_fun(good_id){
      var that = this; 
      app.AppHttp('api/Shopping/getStockAuxUnit', {
        order_id:0,
        good_id:good_id,
        client_id:that.data.loginInfo.id
      }, function (res) {
        that.setData({
          is_move_gif:false,
          aux_kucun_list:res.data
        });
        if(that.data.isinput_col && res.data.length==1){   //当收藏弹窗显示时，才有可能调用
          that.open_tan_info();
        };
      });  
    },
    // 自采在购物车中的的数量
    zicai_pr_num(good_id){
      var that = this; 
      app.AppHttp('api/Shopping/getShopSelfMining', {
        openid:app.globalData.openid,
        good_id:good_id
      }, function (res) {
        if(res.data.data){
          that.setData({
            zi_tannum:res.data.data.pr_num,
            tannum:res.data.data.pr_num,
            shoppr_num:res.data.data.pr_num
          });
        }else{
          that.setData({
            zi_tannum:0,
            tannum:0,
            shoppr_num:0
          });
        };   
      });
    },
    setValue(event){
      this.setData({
        inputNum: this.data.content
      });
    },
    fbsetValue(event){
      this.setData({
        inputFBNum: this.data.content
      });
    },
    confirm(event){
      if (this.data.inputNum == 0){
        if(this.data.inputNum != '' || this.data.tannum==0){
          wx.showLoading({
            title:'输入不能为0',
            duration:500
          });
          return;
        }else{
          this.setData({
            inputNum:this.data.tannum
          });
        }  
      };
      var info = this.data.rightDatas[this.data.inputIndex];
      if (this.data.inputNum > 9999.99) {
        wx.showToast({
          title: '数量过大',
        })
        return;
      };
      info.pr_num = this.data.inputNum == '' ? 0 : this.data.inputNum * 1;
      var aux_obj={'is_aux':0,'pr_unit':this.data.tanunit_index,'sub_unit_num':1};
      if(info.price_type==1 || info.price_type==2){  //非企业独立版
        app.myMethod.updateGood(-1,0,info.id, info.pr_num, this.data.tszhcontent,info.true_price,info.true_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      }else if(info.price_type==3){
        if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){ //模式5
          if(this.data.tan_shop_ku==1){  //库存
            if(this.data.loginInfo.is_ctrl_stock==1 && info.pr_num>0 && info.pr_num*1>this.data.tan_ku_num*1){
              wx.showLoading({
                title:'库存不足',
                duration:500
              });
              return;
            };
            var kucun_price_obj={'true_price':this.data.tan_ku_price,'single_price':0};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              if(this.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
                return;
              };
              var aux_item=this.data.aux_kucun_list[this.data.aux_kucun_index];
              aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
              if(this.data.shop_is_same==0){  //是否开启采销同价
                kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
              }else if(this.data.shop_is_same==1){
                kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
              };
            };
            app.myMethod.updateGood(-1,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          }else if(this.data.tan_shop_ku==0){  //非库存
            if(this.data.loginInfo.is_zi_cai==0 || this.data.assign_super_index>-1){  //非自采
              if(this.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
                return;
              };
              var assign_item=this.data.assign_superlist[this.data.assign_super_index];
              var nor_price_obj={'true_price':info.true_price,'single_price':0};
              if(this.data.tan_is_auxiliary==1){  //是辅助单位
                aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
                nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
              };
              app.myMethod.updateGood(-1,assign_item.supplier_id,info.id, info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
            }else if(this.data.loginInfo.is_zi_cai==1 && this.data.assign_super_index==-10010){  //自采
              app.myMethod.updateGood(-10010,-10010,info.id, info.pr_num, this.data.tszhcontent,info.true_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
            }    
          };      
        }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){  //模式6,7
          app.myMethod.updateGood(-1,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,info.true_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{    //模式1,4及其他
          app.myMethod.updateGood(-1,0,info.id, info.pr_num, this.data.tszhcontent,info.true_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);     
        };
      }else if(info.price_type==4){
        if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
          if(this.data.tan_shop_ku==1){  //库存
            if(this.data.loginInfo.is_ctrl_stock==1 && info.pr_num>0 && info.pr_num*1>this.data.tan_ku_num*1){
              wx.showLoading({
                title:'库存不足',
                duration:500
              });
              return;
            };
            var kucun_price_obj={'true_price':this.data.tan_ku_price,'single_price':this.data.tan_ku_price};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              if(this.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
                return;
              };
              var aux_item=this.data.aux_kucun_list[this.data.aux_kucun_index];
              aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
              if(this.data.shop_is_same==0){  //是否开启采销同价
                kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
              }else if(this.data.shop_is_same==1){
                kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
              };
            };
            app.myMethod.updateGood(-1,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          }else if(this.data.tan_shop_ku==0){  //非库存
            if(this.data.loginInfo.is_zi_cai==0 || this.data.assign_super_index>-1){  //非自采
              if(this.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
                return;
              };
              var assign_item=this.data.assign_superlist[this.data.assign_super_index];
              var nor_price_obj={'true_price':assign_item.unit_price,'single_price':assign_item.unit_price};
              if(this.data.tan_is_auxiliary==1){  //是辅助单位
                aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
                nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
              };
              app.myMethod.updateGood(-1,assign_item.supplier_id,info.id, info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
            }else if(this.data.loginInfo.is_zi_cai==1 && this.data.assign_super_index==-10010){  //自采
              app.myMethod.updateGood(-10010,-10010,info.id, info.pr_num, this.data.tszhcontent,info.true_price,info.true_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
            };   
          };        
        }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){  //模式6,7
          app.myMethod.updateGood(-1,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,info.true_price,info.true_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{   //模式1,4及其他
          app.myMethod.updateGood(-1,0,info.id, info.pr_num, this.data.tszhcontent,info.true_price,info.true_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);     
        };
      }else if(info.price_type==5){
        if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
          if(this.data.tan_shop_ku==1){   //库存商品
            if(this.data.loginInfo.is_ctrl_stock==1 && info.pr_num>0 && info.pr_num*1>this.data.tan_ku_num*1){
              wx.showLoading({
                title:'库存不足',
                duration:500
              });
              return;
            };
            var kucun_price_obj={'true_price':this.data.tan_ku_price,'single_price':this.data.tan_ku_price};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              if(this.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
                return;
              };
              var aux_item=this.data.aux_kucun_list[this.data.aux_kucun_index];
              aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
              if(this.data.shop_is_same==0){  //是否开启采销同价
                kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
              }else if(this.data.shop_is_same==1){
                kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
              };
            };
            app.myMethod.updateGood(-1,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          }else if(this.data.tan_shop_ku==0){   //非库存商品
            if(this.data.loginInfo.is_zi_cai==0 || this.data.assign_super_index>-1){  //非自采
              if(this.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
                return;
              };
              var assign_item=this.data.assign_superlist[this.data.assign_super_index];
              var nor_price_obj={'true_price':assign_item.unit_price,'single_price':assign_item.unit_price};
              if(this.data.tan_is_auxiliary==1){  //是辅助单位
                aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
                nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
              };
              app.myMethod.updateGood(-1,assign_item.supplier_id,info.id, info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
            }else if(this.data.loginInfo.is_zi_cai==1 && this.data.assign_super_index==-10010){  //自采
              app.myMethod.updateGood(-10010,-10010,info.id, info.pr_num,this.data.tszhcontent,info.sale_price,info.sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
            }     
          };      
        }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){   //模式6,7
          app.myMethod.updateGood(-1,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,info.sale_price,info.sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{    //模式1,4及其他
          app.myMethod.updateGood(-1,0,info.id, info.pr_num, this.data.tszhcontent,info.sale_price,info.sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        };
      };
      util.hideBuyModal(this,"isInput");
      if (info.pr_num>0){
        util.touchOnGoods(this,event.touches["0"],-1,'nopand',1);
      }else{
        util.car_total(this,-1,1);
      }
      this.setData({
        ["rightDatas[" + this.data.inputIndex + "]"]: info,
        inputNum: "",
        tannum:'',
        tszhcontent: '',
        inputIndex:-1
      });     
    },
    // 关闭商品数量弹窗
    cancel() {
      util.hideBuyModal(this,"isInput");
      this.setData({
        inputIndex: -1,
        inputNum: "",
        tannum:'',
        shopnum:'',
        shoppr_num:'',
        tszhcontent: '',
        tangui: ""
      });
    },
    // 去搜索添加商品
    searchTap(){   
      var id = -1;
      wx.navigateTo({
        url: '/pages/shangpin/shangpindetail/search/search?id=' + id + '&supername=' + this.data.supername+ '&show_price_type=' + 'A'+'&price_type='+1
      })   
    },
    // 打开添加非标品弹窗
    addFBTap(){
      this.setData({
        isfeibiao: true,
        fbNum:0,
        fbName:"",
        firstPerson:"",
        z_choose_supplier_id:-1
      });  
    },
    // 关闭添加非标品弹窗
    feibiaocancel(){
      this.setData({
        isfeibiao: false,
        tszhcontent: ''
      });
    },
    // 选择供应商
    chose_super(){
      var that = this;
      util.showBuyModal(that); 
      that.setData({
        issuper:true
      }); 
      app.AppHttp("api/Client/belongBusinessSupplier", {
        client_id:app.globalData.loginInfo.id
      }, function(res) { 
        that.setData({
          btm_superlist:res.data
        });
      });
    },
    // 确定供应商
    super_conf(e){
      var supplier_id=e.currentTarget.dataset.supplier_id;
      var company_name=e.currentTarget.dataset.company_name;
      this.setData({
        z_choose_supplier_id:supplier_id,
        z_choose_supplier_name:company_name
      });
      util.hideBuyModal(this,"issuper");
    },
    // 关闭供应商
    close_super(){
      util.hideBuyModal(this,"issuper");
    },
    /**
     * 非标品确认添加
     */
    feibiaoconfirm(event) {
      var that = this;
      var fbNum = that.data.fbNum;
      var fbName = that.data.fbName;
      var fbDanWei = that.data.value;
      var supplier_id = -1;
      if (fbName == '') {
        wx.showLoading({
          title:'请输入名称',
          duration:500
        });
      }else if (fbDanWei == '') {
        wx.showLoading({
          title:'请选择单位',
          duration:500
        });
      }else{
        var z_choose_supplier_id=0; //0代表不选供应商
        if(that.data.good_dir_set==2 && that.data.client_is_store==0 && that.data.purchase_type==1){ //模式5  
          if(that.data.z_choose_supplier_id==-1){
            wx.showLoading({
              title:'请选择供应商',
              duration:500
            });
            return;
          }else{
            z_choose_supplier_id=that.data.z_choose_supplier_id;
            if(z_choose_supplier_id==-10010){  //选择了自采
              supplier_id=-10010;
            };
          };
        };
        wx.request({
          url: app.globalData.url + 'api/Goods/addNoProductDo',
          method: 'POST',
          data: {
            openid: app.globalData.openid,
            supplier_id: supplier_id,
            b_supplier_id:that.data.good_dir_set==2 && that.data.purchase_type==2?that.data.group_id:z_choose_supplier_id,    //模式6,7选企业的id
            pr_name: "**"+fbName,
            pr_unit: fbDanWei,
            num: fbNum,
            remark: that.data.tszhcontent,
            one_class:0,
            is_ku:1
          },
          success: function (res) {
            console.log(JSON.stringify(res.data))
            if (fbNum>0){
              that.setData({
                isfeibiao: false
              });
              util.touchOnGoods(that,event.touches["0"],-1,'nopand',1); 
            }else{
              wx.showLoading({
                title: res.data.msg,
                duration:500
              });
            }    
          },
        })
        that.setData({
          tszhcontent: ''
        })
      }      
    },
    fbminTap(event){
      var fbNum = event.currentTarget.dataset.id;
      if(fbNum<1){
        fbNum=0;
      }else{
        fbNum--; 
        if((fbNum*1)%1!=0){
          fbNum=parseFloat((fbNum*1).toFixed(2));
        };  
      };
      this.setData({
        fbNum: fbNum,
        holderFBNum: fbNum
      });
    },
    fbnumInput(event){
      util.showBuyModal(this);
      var index = event.currentTarget.dataset.id;;
      this.setData({
        content:'',
        isInput:true,
        tan_sale_price:'',
        inputIndex: index,
        holderFBNum: this.data.fbNum,
        inputFBNum: '',
        assign_super_index:-1,
        is_move_gif:false,
        assign_superlist:[],
        tanimg:'/upload/smallprogram/noshopimg.png',
        tanname: this.data.fbName?this.data.fbName:'未填写名称',
        tanunit: this.data.firstPerson
      });
    },
    fbaddTap(event){
      var fbNum = event.currentTarget.dataset.id;
          fbNum = parseFloat(fbNum);
          fbNum ++ ;
      this.setData({
        fbNum: fbNum,
        holderFBNum: fbNum
      });
    },
    // 非标品名称输入
    setFBName(event){
      var fbName = event.detail.value;
      this.setData({
        fbName:fbName
      })
    },
    // 非标品单位弹窗
    setFBDanWei(event){
      var selectdanwei = this.data.selectdanwei;
      if (selectdanwei == true) {
        util.hideBuyModal(this,"selectdanwei");   
      } else {
        util.showBuyModal(this);
        this.setData({
          selectdanwei: true
        })
      };
      this.feibiao();
    },
    confirmfb(){
      if (this.data.inputFBNum > 9999.99) {
        wx.showToast({
          title: '数量过大',
        })
        return;
      }
      if (this.data.inputFBNum == ''){
          util.hideBuyModal(this,"isInput");
          this.setData({
            holderFBNum:""
          });
      }else{
        var fbNum = this.data.inputFBNum * 1;
        util.hideBuyModal(this,"isInput");
        this.setData({
          fbNum:fbNum,
          holderFBNum:""
        });
      }  
    },
    // 刷新数据(商品库)
    upshoplist(){
      if(this.data.page==1){
        wx.showLoading({
          title: this.data.load
        });
      }; 
      var that=this;
      app.AppHttp('api/Supplier/good_manage', {
        openid: app.globalData.openid,
        id: app.globalData.loginInfo.id,
        e_type:'client',
        page: that.data.page,
        limit: 20,
        one_id: one_id,
        two_id: two_id
      }, function (res) {
        that.setData({
          loading:0,
          load_num:0,
          types: res.data.one_class_list,
          leftTypes: res.data.two_class_list,
          allpage: res.data.goodList[1]
        }); 
        if(that.data.page==1){
          that.setData({
            rightDatas: res.data.goodList[0]
          });
        }else{
          that.setData({
            rightDatas: that.data.rightDatas.concat(res.data.goodList[0])
          });
        };
        wx.hideLoading()
      });
    },
    // 刷新页面(常用)
    upshoplist_often(){
      var that = this;
      wx.showLoading({
        title: '加载中...'
      });
      app.AppHttp('api/Shopping/cliCollGoodList', {
        openid: app.globalData.openid,
        supplier_id: -1,
        is_ku:1
      }, function (res) {
        if (res.data.status == -1){
          that.setData({
            nocoll:0,
            isedit:false,
            superlist:[],
            cate_list:[],
            coll_list:[],
            total:0
          });
          wx.hideLoading();
          return;
        };
        that.setData({
          superlist: res.data.coop_list,  //供应商列表
          cate_list: res.data.coll_list.cate_list,  //左侧分类列表
          coll_list: res.data.coll_list.result,   //收藏列表
          nocoll: res.data.coll_list.result.length==0?0:1,
          isedit:res.data.coll_list.result.length==0?false:that.data.isedit,
          ids: [],    //每次刷新清空ids数组
          is_checked: {},   //选中状态清空
          checked_len:0,  //选中数目
          status: 1     //1正常 0暂时合作 -1待审核
        });
        if (res.data.coll_list.cate_list.length > 0 && that.data.load_num==1){
          that.setData({
            toView: "b" + res.data.coll_list.cate_list[that.data.leftChoose_col].private_one_class,  //瞄点索引值
            load_num:0
          }); 
        }; 
        wx.hideLoading();
      });
    },
    // 左侧切换选择(常用)
    leftClick_col(e){
      var name = e.currentTarget.dataset.name;
      let offsetTop = e.currentTarget.offsetTop;   
      this.setData({
        scrollLeft: offsetTop - this.data.left_height/2,
        leftChoose_col: e.currentTarget.dataset.index,
        toView: name,
      });
    },
    // 编辑
    edit_but(){
      this.setData({
        isedit: true
      });
    },
    // 完成编辑
    conf_editck(){
      this.setData({
        isedit: false
      })
    },
    // 收藏表单改变
    collChange(e){
      var is_checked = {};
      for (var i = 0; i < e.detail.value.length; i++) {
        is_checked[e.detail.value[i]] = true;
      };
      this.setData({
        is_checked:is_checked,
        checked_len:e.detail.value.length
      });
    },
    // 添加商品弹窗
    itemAddClick_col(e){
      var specs_count=e.currentTarget.dataset.specs_count;  //是否有规格
      var index=e.currentTarget.dataset.index;
      var eal=e.currentTarget.dataset.eal;
      var is_up=e.currentTarget.dataset.is_up;  //是否下架，(未开启辅助单位)有几个供应商
      var is_ku=e.currentTarget.dataset.is_ku;  //是否属于库存商品
      var is_zi_cai=this.data.loginInfo.is_zi_cai;   //客户是否自采
      var tan_is_auxiliary=e.currentTarget.dataset.is_auxiliary;  //是否开启辅助单位
      var is_aux_up=e.currentTarget.dataset.is_aux_up;  //开启辅助单位后，有几条辅助单位
      if (this.data.isedit == false) {
        if(specs_count>0 || this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1 && (tan_is_auxiliary==0 && is_up*1+is_zi_cai*1>1 && is_ku==0 || tan_is_auxiliary==1 && is_aux_up*1+is_zi_cai*1>1 && is_ku==0 || tan_is_auxiliary==1 && is_aux_up*1>1 && is_ku==1)){  //有规格 or 模式5+(多供应商+非库存商品 or 多辅助单位+非库存商品 or 多辅助单位+库存商品)
          if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){
            if(is_ku==1){
              this.setData({
                is_move_gif:tan_is_auxiliary==1?true:false,
                aux_kucun_index:-1,
                aux_kucun_list:[],
                tan_is_auxiliary:tan_is_auxiliary,
                tan_shop_ku:1
              });
              if(tan_is_auxiliary==1){
                this.aux_kucun_fun(e.currentTarget.dataset.good_id);
              };
            }else if(is_ku==0){
              this.setData({
                tan_shop_ku:0,  //当前商品不属于库商品
                assign_superlist:[],
                aux_kucun_index:-1,
                aux_kucun_list:[],
                tan_is_auxiliary:tan_is_auxiliary,
                is_move_gif:true
              });
              this.assign_super_fun(e.currentTarget.dataset.good_id,tan_is_auxiliary);
            };       
          }else{
            this.setData({
              tan_is_auxiliary:tan_is_auxiliary,
              assign_super_index:-1,
              is_move_gif:false
            });
          };
          this.setData({
            shopid: e.currentTarget.dataset.good_id,
            shopck_id: e.currentTarget.dataset.good_id,
            ischoose_index: -1,
            one_index: e.currentTarget.dataset.index,
            shop_is_same:this.data.coll_list[index][eal].is_same,
            eal: e.currentTarget.dataset.eal,
            upshop: 0,
            tszhcontent:''
          });
          this.tancontent();
        }else{       
          util.showBuyModal(this);
          var coll_list = this.data.coll_list;
          if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){
            if(is_ku==1){   //库存商品
              if(this.data.loginInfo.is_ctrl_stock==1 && this.data.coll_list[index][eal].stock_num_show*1<=0){
                wx.showLoading({
                  title:'库存不足',
                  duration:500
                });
                return;
              };
              this.setData({
                is_move_gif:tan_is_auxiliary==1?true:false,
                tan_shop_ku:1,
                tan_is_auxiliary:tan_is_auxiliary,
                aux_kucun_index:tan_is_auxiliary==1?0:-1,
                assign_super_index:-1
              });
              if(tan_is_auxiliary==1){
                this.aux_kucun_fun(e.currentTarget.dataset.good_id);
              };
            }else if(is_ku==0){  //非库存商品
              this.setData({
                tan_shop_ku:0,  //当前商品不属于库商品
                assign_superlist:[],      
              });
              if(is_zi_cai==0){  //非自采
                this.setData({
                  is_move_gif:true,
                  tan_is_auxiliary:tan_is_auxiliary,
                  assign_super_index:0
                });
                this.assign_super_fun(e.currentTarget.dataset.good_id,tan_is_auxiliary);
              }else if(is_zi_cai==1){  //自采
                this.setData({
                  assign_super_index:-10010,
                  tan_is_auxiliary:tan_is_auxiliary,
                  is_move_gif:false
                });
              };
            };      
          }else{
            this.setData({
              tan_is_auxiliary:tan_is_auxiliary,
              assign_super_index:-1,
              is_move_gif:false
            })
          };
          this.setData({
            content:'',
            isInput:true,
            shopid: e.currentTarget.dataset.good_id,
            ischoose_index:0,
            tanimg: coll_list[index][eal].cover,
            tanname: coll_list[index][eal].trade_name,
            tanalias:'',
            tanunit_index: coll_list[index][eal].help_unit>0?coll_list[index][eal].help_unit:coll_list[index][eal].unit,
            tanunit: coll_list[index][eal].help_unit>0?coll_list[index][eal].help_unit_name:coll_list[index][eal].unit_name,
            tanunit_init:coll_list[index][eal].unit_name,
            tan_price_type:coll_list[index][eal].price_type,    //price_type
            tan_true_price:coll_list[index][eal].true_price,
            tan_sale_price:coll_list[index][eal].sale_price,
            shopnum: '',
            shoppr_num:coll_list[index][eal].pr_num,  //产品是否已添加
            shop_price_type:coll_list[index][eal].price_type,  //产品价格类型
            shop_price:coll_list[index][eal].true_price, //产品的价格
            shop_sale_price:coll_list[index][eal].sale_price,  //产品销售价
            shop_is_same:coll_list[index][eal].is_same,  //是否开启了采销同价
            tan_ku_price:coll_list[index][eal].is_same==0?coll_list[index][eal].stock_sale_price:coll_list[index][eal].stock_price_show,
            tan_ku_num:coll_list[index][eal].stock_num_show,
            is_tan_ku_price:coll_list[index][eal].is_show_stock_price,
            is_tan_ku_num:coll_list[index][eal].is_show_stock_num
          });   
        }
      }
    },
    // 表单提交
    formSubmit(e){
      var that = this;
      var ids = e.detail.value.colltype;  //选中的ids数组
      that.setData({
        ids: ids
      });
      if (ids.length != 0) {
        wx.showModal({
          title: '提示',
          content: '请确定移除',
          success: function (res) {
            if (res.confirm) {
              app.AppHttp('api/Shopping/removeCallGoods', {
                ids: ids
              }, function (res) {
                that.upshoplist_often();
              })
            }
          }
        });
      } else {
        wx.showToast({
          title: '请至少选择一种商品',
          duration: 500,
          icon: "loading"
        })
      }
    },
    // 键盘按键
    keyTap(e) {
      util.keyfunction(e,this,3);
      if(this.data.isfeibiao==true){
        this.fbsetValue();
      }else if(this.data.isinput_col==true || this.data.page_type==1){
        this.col_setValue();
      }else{
        this.setValue();
      };
    },
    // 右侧列表上拉触底事件
    scroll_btom(){
      if(this.data.page_type==0){
        if (this.data.page < this.data.allpage) {
          this.setData({
            page: this.data.page + 1,
            isChooseAll: false,
            loading:1,
            load: '加载更多'
          });
          this.upshoplist();
        } else {
          wx.showToast({
            title: '没有了'
          });
          this.setData({
            loading:0
          });
        }
      };   
    },
  }
})